package StackAndQueue;

import java.util.Stack;


public class Solution
{
    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<s.length();i++)
        {
            char value=s.charAt(i);
            if (value=='{'||value=='['||value=='(')
            {
                stack.push(value);
            }
            else
            {
                if (stack.isEmpty())
                    return false;
                char out=stack.pop();
                if (out=='{'&&value!='}')
                    return false;
                if (out=='['&&value!=']')
                    return false;
                if (out=='('&&value!=')')
                    return false;
            }
        }
        return stack.isEmpty();
    }

}
